package com.sylar.happygps;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.sylar.happygps.adapter.ContactAdapter;

public class UserContaActivity extends Activity implements OnClickListener {
	private ContactAdapter contactAdapter;
	private Button btn_edit;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.usercontact);

		Button btn_title_left = (Button) findViewById(R.id.btn_title_left);
		btn_title_left.setVisibility(View.VISIBLE);
		btn_title_left.setText("用户中心");
		btn_title_left.setOnClickListener(this);
		

		Button btn_help = (Button) findViewById(R.id.btn_help);
		btn_help.setText("添加");
		btn_help.setVisibility(View.VISIBLE);
		btn_help.setOnClickListener(this);
		
		btn_edit = (Button) findViewById(R.id.btn_edit);
		btn_edit.setVisibility(View.VISIBLE);
		btn_edit.setOnClickListener(this);

		TextView tv_title_name = (TextView) findViewById(R.id.tv_title_name);
		tv_title_name.setVisibility(View.VISIBLE);
		tv_title_name.setText("联系人");
		
		
		
		ListView contact_list = (ListView) findViewById(R.id.contact_list);
		
//		View headView = LayoutInflater.from(this).inflate(R.layout.search, null);
//		contact_list.addHeaderView(headView, null, false);
		
		
		contactAdapter = new ContactAdapter(this);
		contact_list.setAdapter(contactAdapter);
		
//		contactAdapter.setShowItem2(true);  设置是否显示联系人第二行信息
//		contactAdapter.notifyDataSetChanged();
	}

	private void toEditContact(){
		Intent intent = new Intent(this,ContactEditActivity.class);
		startActivity(intent);
	}
	
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_title_left:
			finish();
			break;
		case R.id.btn_title_right:
			
			break;
		case R.id.btn_help:
			toEditContact();
			break;
		case R.id.btn_edit:
			if(btn_edit!=null ){
				if(contactAdapter!=null){
					if(contactAdapter.getDel()){
						contactAdapter.setDel(false);
						contactAdapter.notifyDataSetChanged();
					}else{
						contactAdapter.setDel(true);
						contactAdapter.notifyDataSetChanged();
					}
				}
			}
			break;
			
			
		default:
			break;
		}
	}
}
